#ifndef __I2C_MPU6050_H__
#define __I2C_MPU6050_H__

#include "iic.h"

#define DEV_CNT                 1
#define CHRDEV_NAME             "mpu6050"

struct iic_dev mpudev;

#define WHO_AM_I        0x75
#define PWR_MGMT_1      0x6B
#define SMPLRT_DIV      0x19
#define CONFIG          0x1A

#define GYRO_CONFIG     0x1B
#define ACCEL_CONFIG    0x1C

#define ACCEL_XOUT_H    0x3B
#define ACCEL_XOUT_L    0x3C
#define ACCEL_YOUT_H    0x3D
#define ACCEL_YOUT_L    0x3E
#define ACCEL_ZOUT_H    0x3F
#define ACCEL_ZOUT_L    0x40

#define GYRO_XOUT_H     0x43
#define GYRO_XOUT_L     0x44
#define GYRO_YOUT_H     0x45
#define GYRO_YOUT_L     0x46
#define GYRO_ZOUT_H     0x47
#define GYRO_ZOUT_L     0x48

#define TEMPERATURE_H   0x41
#define TEMPERATURE_L   0x42


#define ACCEL_XOUT      ((ACCEL_XOUT_H << 8) | ACCEL_XOUT_L)
#define ACCEL_YOUT      ((ACCEL_YOUT_H << 8) | ACCEL_YOUT_L)
#define ACCEL_ZOUT      ((ACCEL_ZOUT_H << 8) | ACCEL_ZOUT_L)
#define GYRO_XOUT       ((GYRO_XOUT_H << 8) | GYRO_XOUT_L)
#define GYRO_YOUT       ((GYRO_YOUT_H << 8) | GYRO_YOUT_L)
#define GYRO_ZOUT       ((GYRO_ZOUT_H << 8) | GYRO_ZOUT_L)
#define TEMPERATURE     ((TEMPERATURE_H << 8) | TEMPERATURE_L)

#define FS_SEL          0x11    // 陀螺仪量程，±2000°/s
#define GYRO_SCALE      (FS_SEL << 3)
#define AFS_SEL         0x00
#define ACCEL_SCALE     (AFS_SEL << 3)



static int mpu6050_open(struct inode *inode, struct file *filp);
static ssize_t mpu6050_read(struct file *filp, char __user *buf, size_t cnt, loff_t *offt);
static int mpu6050_release(struct inode *inode, struct file *filp);

static int mpu6050_probe(struct i2c_client *client, const struct i2c_device_id *id);
static int mpu6050_remove(struct platform_device *dev);

static int mpu6050_init(void);
static short mpu6050_getData(int data_type);

/* 总线设备注册 */
const struct i2c_device_id iic_device_id[] = {
    {"mpu6050,INV_MPU6050", 0},
    {}
};

const struct of_device_id iic_of_match[] = {
    { .compatible = "mpu6050,INV_MPU6050" },
    { /* Sentinel */ }
};

static struct i2c_driver mpu6050_driver = {
    .probe = mpu6050_probe,
    .remove = mpu6050_remove,
    .driver = {
        .owner = THIS_MODULE,
        .name = "mpu6050_i2c",
        .of_match_table = iic_of_match,
    },
    .id_table = iic_device_id,
};

#endif
